package com.mingqijia.gassafety.job.strategy.impl;

import com.alibaba.fastjson.JSONObject;
import com.mingqijia.gassafety.db.entity.InformRecord;
import com.mingqijia.gassafety.db.mapper.InformRecordMapper;
import com.mingqijia.gassafety.job.dto.SendMessageDTO;
import com.mingqijia.gassafety.job.strategy.RecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * <p>
 * 服务超期 策略实现
 * </p>
 *
 * @author mby
 * @since 2024-01-16
 */
@Service
@Slf4j
public class InformRecordService implements RecordService { // 实现策略


    @Autowired
    InformRecordMapper informRecordMapper;

    /**
     * 保存服务提醒通知记录
     * @param dto 服务提醒基础数据
     * @param date 时间
     * @param errorMessage 错误信息
     * @param receiptCode 回执编码
     * @param sendResult 发送结果
     * @param status 执行状态
     */
    public void saveWarningRecord(SendMessageDTO dto, Date date, String errorMessage, String receiptCode, Integer sendResult, Integer status) {
        InformRecord warningRecord = new InformRecord();
        warningRecord.setConsumerId(String.valueOf(dto.getConsumerId()));
        warningRecord.setStartTime(date);
        warningRecord.setEndTime(date);
        warningRecord.setTriggerRuleId(dto.getStrategyId());
        warningRecord.setIMEI(dto.getImei());
        warningRecord.setTaskIdentificationCode(String.valueOf(dto.getSnowflakeId()));
        warningRecord.setSendType(dto.getPushType());
        warningRecord.setObjLevel(dto.getLevel());
        warningRecord.setSpId(dto.getSpId());
        warningRecord.setSendResult(sendResult);
        warningRecord.setStatus(status);
        warningRecord.setContent(dto.getContent());
        warningRecord.setReceiptCode(receiptCode);
        warningRecord.setPushPhone(dto.getPhone());
        warningRecord.setRemark(!StringUtils.isEmpty(errorMessage) ? errorMessage : "发送成功");
        log.info("saveInformRecord:{}", JSONObject.toJSONString(warningRecord));
        informRecordMapper.insert(warningRecord);
    }

}
